package com.bwie.controller;
import com.bwie.pojo.Area;
import com.bwie.pojo.Repairs;
import com.bwie.pojo.Type;
import com.bwie.service.AreaService;
import com.bwie.service.RepairsService;
import com.bwie.service.TypeService;
import com.bwie.service.UserFeignService;
import com.bwie.service.impl.RepairsServiceImpl;
import com.bwie.utils.R;
import com.bwie.vo.RepairsPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
* (t_repairs)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/repairs/index")
public class RepairsController {
/**
* 服务对象
*/
    @Autowired
    private RepairsService repairsService;

    @Autowired
    TypeService typeService;

    @Autowired
    AreaService areaService;

    @Autowired
    UserFeignService userFeignService;

    /**
     * @author: 秋晚
     * @description:2.	对报修记录表的报修时间进行统计，以折线图的形式展示近两周每天的报修数量
     * @params: []
     * @return: com.bwie.utils.R
     * @date: 2025/7/8 14:21
     */
    @PostMapping("getXyData")
    public R getXyData(){
        return repairsService.getXyData();
    }

    /**
     * @author: 秋晚
     * @description:3.	对报修记录表的报修时间、维修状态进行统计，以柱形图的形式展示近一年中每月的维修状态占比
     * @params: []
     * @return: com.bwie.utils.R
     * @date: 2025/7/8 14:21
     */
    @PostMapping("getStatusXy")
    public R getStatusXy(){
        return repairsService.getStatusXy();
    }

    @PostMapping("getAreaXy")
    public R getAreaXy(){
        return repairsService.getAreaXy();
    }

    @PostMapping("repairsPage")
    public R repairsPage(@RequestBody RepairsPageVo repairsPageVo){
        return repairsService.repairsPage(repairsPageVo);
    }

    @PostMapping("getAllType")
    public R getAllType(){
        List<Type> list = typeService.list();
        return R.OK(list);
    }

  @PostMapping("getAllArea")
    public R getAllArea(){
        List<Area> list = areaService.list();
        return R.OK(list);
    }

    @PostMapping("saveRepairs")
    public R saveRepairs(@RequestBody @Validated Repairs repairs){
        return repairsService.saveRepairs(repairs);
    }

    @PostMapping("uploadFile")
    public R uploadFile(@RequestPart MultipartFile file){
        return repairsService.uploadFile(file);
    }

    @PostMapping("editRepairs")
    public R editRepairs(@RequestBody @Validated Repairs repairs){
        return repairsService.editRepairs(repairs);
    }

    @PostMapping("getRecordById/{id}")
    public R getRecordById(@PathVariable(name = "id") Long id){
        return repairsService.getRecordById(id);
    }


    @PostMapping("upRepairsStatus")
    public R upRepairsStatus(@RequestBody Repairs repairs){
        return repairsService.upRepairsStatus(repairs);
    }


    @ApiOperation("获取用户")
    @PostMapping("getUser/{id}")
    public R getUser(@PathVariable(name = "id") Long id){
        R r = userFeignService.getUserById(id);
        return R.OK(r);
    }

    @ApiOperation("导出excel")
    @GetMapping("exportExcel")
    public void exportExcel(){
        repairsService.exportExcel();
    }

    @ApiOperation("导入excel")
    @PostMapping("importExcel")
    public R importExcel(@RequestPart MultipartFile file){
        return repairsService.importExcel(file);
    }


    @ApiOperation("获取xy轴数据")
    @PostMapping("getEcharts")
    public R getEcharts(){
        return repairsService.getEcharts();
    }
}
